{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c8d415e2",
   "metadata": {},
   "source": [
    "## （一）字典_任务"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "218dd0de",
   "metadata": {},
   "source": [
    "> 1.面部测试，获取一张图片的数据，通过访问字典，查询该面部数据的：\n",
    ">> 取内容：性别 gender、年龄、有无眼睛、头发状况、hairColor中的color为red的confidence值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "9f307b08",
   "metadata": {},
   "outputs": [],
   "source": [
    "people = [\n",
    "   {\n",
    "     \"faceId\": \"29867cfe-ba72-41a3-8407-57b7f110633b\",\n",
    "     \"faceRectangle\": {\n",
    "                           \"top\": 128,\n",
    "                           \"left\": 459,\n",
    "                           \"width\": 224,\n",
    "                           \"height\": 224 },\n",
    "     \"faceAttributes\": {\n",
    "                        \"hair\": {\n",
    "                                 \"bald\": 0.1,\n",
    "                                 \"invisible\": False,\n",
    "                                 \"hairColor\": [\n",
    "                                                   { \"color\": \"brown\",\n",
    "                                                     \"confidence\": 0.99 },\n",
    "                                                   {\"color\": \"black\",\n",
    "                                                     \"confidence\": 0.57 },\n",
    "                                                   {\"color\": \"red\",\n",
    "                                                     \"confidence\": 0.36},\n",
    "                                                   { \"color\": \"blond\",\n",
    "                                                     \"confidence\": 0.34 },\n",
    "                                                   {\"color\": \"gray\",\n",
    "                                                    \"confidence\": 0.15},\n",
    "                                                   {\"color\": \"other\",\n",
    "                                                    \"confidence\": 0.13}\n",
    "                                                 ]\n",
    "                                   },\n",
    "       \"smile\": 1.0,\n",
    "       \"headPose\": {\n",
    "                     \"pitch\": -13.2,\n",
    "                     \"roll\": -11.9,\n",
    "                     \"yaw\": 5.0\n",
    "                   },\n",
    "       \"gender\": \"female\",\n",
    "       \"age\": 24.0,\n",
    "       \"facialHair\": {\n",
    "                         \"moustache\": 0.0,\n",
    "                         \"beard\": 0.0,\n",
    "                         \"sideburns\": 0.0\n",
    "                       },\n",
    "       \"glasses\": \"ReadingGlasses\",\n",
    "       \"makeup\": {\n",
    "                     \"eyeMakeup\": True,\n",
    "                     \"lipMakeup\": True\n",
    "                   },\n",
    "       \"emotion\": {\n",
    "                     \"anger\": 0.0,\n",
    "                     \"contempt\": 0.0,\n",
    "                     \"disgust\": 0.0,\n",
    "                     \"fear\": 0.0,\n",
    "                     \"happiness\": 1.0,\n",
    "                     \"neutral\": 0.0,\n",
    "                      \"sadness\": 0.0,\n",
    "                      \"surprise\": 0.0\n",
    "                    },\n",
    "        \"occlusion\": [\n",
    "                    {\n",
    "                          \"forehead0ccluded\": False,\n",
    "                          \"eye0ccluded\": False,\n",
    "                          \"mouth0ccluded\": False\n",
    "                      }\n",
    "                        ],\n",
    "        \"accessories\": [\n",
    "                          {\n",
    "                            \"type\": \"glasses\",\n",
    "                            \"confidence\": 1.0\n",
    "                          }\n",
    "                        ],\n",
    "        \"blur\": {\n",
    "                      \"blurLevel\": \"low\",\n",
    "                      \"value\": 0.0\n",
    "                    },\n",
    "        \"exposure\": {\n",
    "                      \"exposureLevel\": \"goodExposure\",\n",
    "                      \"value\": 0.48\n",
    "                    },\n",
    "        \"noise\": {\n",
    "                      \"noiseLevel\": \"low\",\n",
    "                      \"value\": 0.0\n",
    "                    }\n",
    "      },\n",
    "       \n",
    "      \"faceLandmarks\": {\n",
    "        \"pupilLeft\": {\n",
    "                          \"x\": 504.8,\n",
    "                          \"y\": 206.8\n",
    "                        },\n",
    "        \"pupilRight\": {\n",
    "                          \"x\": 602.5,\n",
    "                        \"y\": 178.4\n",
    "                      },\n",
    "      \"noseTip\": {\n",
    "                        \"x\": 593.5,\n",
    "                        \"y\": 247.3\n",
    "                      },\n",
    "      \"mouthLeft\": {\n",
    "                        \"x\": 529.8,\n",
    "                        \"y\": 300.5\n",
    "                      },\n",
    "      \"mouthRight\": {\n",
    "                        \"x\": 626.0,\n",
    "                        \"y\": 277.3\n",
    "                      },\n",
    "      \"eyebrowLeftOuter\": {\n",
    "                        \"x\": 461.0,\n",
    "                        \"y\": 186.8\n",
    "                      },\n",
    "      \"eyebrowLeftInner\": {\n",
    "                        \"x\": 541.9,\n",
    "                         \"y\": 178.9\n",
    "                       },\n",
    "       \"eyeLeftOuter\": {\n",
    "                         \"x\": 490.9,\n",
    "                         \"y\": 209.0\n",
    "                       },\n",
    "       \"eyeLeftTop\": {\n",
    "                         \"x\": 509.1,\n",
    "                         \"y\": 199.5\n",
    "                       },\n",
    "       \"eyeLeftBottom\": {\n",
    "                         \"x\": 509.3,\n",
    "                         \"y\": 213.9\n",
    "                       },\n",
    "       \"eyeLeftInner\": {\n",
    "                         \"x\": 529.0,\n",
    "                         \"y\": 205.0\n",
    "                       },\n",
    "       \"eyebrowRightInner\": {\n",
    "                         \"x\": 579.2,\n",
    "                         \"y\": 169.2\n",
    "                       },\n",
    "       \"eyebrowRightOuter\": {\n",
    "                         \"x\": 633.0,\n",
    "                         \"y\": 136.4\n",
    "                       },\n",
    "       \"eyeRightInner\": {\n",
    "                         \"x\": 590.5,\n",
    "                         \"y\": 184.5\n",
    "                       },\n",
    "       \"eyeRightTop\": {\n",
    "                         \"x\": 604.2,\n",
    "                         \"y\": 171.5\n",
    "                       },\n",
    "       \"eyeRightBottom\": {\n",
    "                         \"x\": 608.4,\n",
    "                         \"y\": 184.0\n",
    "                       },\n",
    "       \"eyeRightOuter\": {\n",
    "                         \"x\": 623.8,\n",
    "                         \"y\": 173.7\n",
    "                       },\n",
    "       \"noseRootLeft\": {\n",
    "                         \"x\": 549.8,\n",
    "                         \"y\": 200.3\n",
    "                       },\n",
    "       \"noseRootRight\": {\n",
    "                         \"x\": 580.7,\n",
    "                         \"y\": 192.3\n",
    "                       },\n",
    "       \"noseLeftAlarTop\": {\n",
    "                         \"x\": 557.2,\n",
    "                         \"y\": 234.6\n",
    "                       },\n",
    "       \"noseRightAlarTop\": {\n",
    "                         \"x\": 603.2,\n",
    "                         \"y\": 225.1\n",
    "                       },\n",
    "       \"noseLeftAlarOutTip\": {\n",
    "                         \"x\": 545.4,\n",
    "                         \"y\": 255.5\n",
    "                       },\n",
    "       \"noseRightAlarOutTip\": {\n",
    "                         \"x\": 615.9,\n",
    "                         \"y\": 239.5\n",
    "                       },\n",
    "       \"upperLipTop\": {\n",
    "                         \"x\": 591.1,\n",
    "                         \"y\": 278.4\n",
    "                       },\n",
    "       \"upperLipBottom\": {\n",
    "                         \"x\": 593.2,\n",
    "                         \"y\": 288.7\n",
    "                       },\n",
    "       \"underLipTop\": {\n",
    "                         \"x\": 597.1,\n",
    "                         \"y\": 308.0\n",
    "                       },\n",
    "       \"underLipBottom\": {\n",
    "                             \"x\": 600.3,\n",
    "                             \"y\": 324.8    \n",
    "                           }\n",
    "     }\n",
    "   }\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "968770c4",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'gender': 'female',\n",
       " 'age': 24.0,\n",
       " 'eyeoccluded': False,\n",
       " 'haircolor': 0.36,\n",
       " 'hair': {'bald': 0.1,\n",
       "  'invisible': False,\n",
       "  'hairColor': [{'color': 'brown', 'confidence': 0.99},\n",
       "   {'color': 'black', 'confidence': 0.57},\n",
       "   {'color': 'red', 'confidence': 0.36},\n",
       "   {'color': 'blond', 'confidence': 0.34},\n",
       "   {'color': 'gray', 'confidence': 0.15},\n",
       "   {'color': 'other', 'confidence': 0.13}]}}"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face = {}\n",
    "face['gender'] = people[0][\"faceAttributes\"]['gender']\n",
    "face['age'] = people[0][\"faceAttributes\"]['age']\n",
    "face['eyeoccluded'] = people[0][\"faceAttributes\"]['occlusion'][0][\"eye0ccluded\"]\n",
    "face['haircolor'] = people[0][\"faceAttributes\"]['hair']['hairColor'][2]['confidence']\n",
    "face['hair'] = people[0][\"faceAttributes\"]['hair']\n",
    "face"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "66cc7b79",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'age': 24.0,\n",
      " 'eyeoccluded': False,\n",
      " 'gender': 'female',\n",
      " 'hair': {'bald': 0.1,\n",
      "          'hairColor': [{'color': 'brown', 'confidence': 0.99},\n",
      "                        {'color': 'black', 'confidence': 0.57},\n",
      "                        {'color': 'red', 'confidence': 0.36},\n",
      "                        {'color': 'blond', 'confidence': 0.34},\n",
      "                        {'color': 'gray', 'confidence': 0.15},\n",
      "                        {'color': 'other', 'confidence': 0.13}],\n",
      "          'invisible': False},\n",
      " 'haircolor': 0.36}\n"
     ]
    }
   ],
   "source": [
    "import pprint\n",
    "pprint.pprint(face)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f23021ab",
   "metadata": {},
   "source": [
    "&emsp;"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3152067f",
   "metadata": {},
   "source": [
    "## （二）多级地址菜单"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "28f0fd51",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "data = {\n",
    "    \"北京\":{\n",
    "        \"朝阳\":{},\n",
    "        \"海淀\":{},\n",
    "        \"昌平\":{}\n",
    "    },\n",
    "    \"上海\":{\n",
    "        \"黄埔\":{},\n",
    "        \"浦东新区\":{},\n",
    "        \"虹口\":{}\n",
    "    },\n",
    "    \"广东\":{\n",
    "        \"深圳\":{\n",
    "            \"罗湖\":[\"深中华\",\"世纪星源\"],\n",
    "            \"福田\":[\"招商证券\",\"深华发\",\"深科技\",\"深圳会展中心\"],\n",
    "            \"南山\":[\"Tencent\",\"深信服\",\"TCL\"],\n",
    "            \"龙岗\":[\"华为\",\"中兴通讯\"]\n",
    "        },\n",
    "        \"广州\":{},\n",
    "        \"佛山\":{},\n",
    "    },\n",
    "}\n",
    "\n",
    "exit_flag = True\n",
    "\n",
    "while exit_flag:\n",
    "    for i in data:\n",
    "        print(i)                   #打印第一层的key\n",
    "    choice = input(\"选择输入>>>:\")\n",
    "    if choice in data:\n",
    "        while exit_flag:\n",
    "            for i2 in data[choice]:\n",
    "                print(\"\\t\",i2)           # 一个制表符\n",
    "            choice2 = input(\"选择输入>>>:\")\n",
    "            if choice2 == \"back\":     \n",
    "                break\n",
    "            elif choice2 == \"exit\":\n",
    "                exit_flag = False           # 可退出\n",
    "            if choice2 in data[choice]:\n",
    "                while exit_flag:\n",
    "                    for i3 in data[choice][choice2]:       # 访问第2层key\n",
    "                        print(\"\\t\\t\",i3)            # 两个制表符\n",
    "                    choice3 = input(\"选择输入>>>:\")\n",
    "                    if choice3 == \"back\":\n",
    "                        break\n",
    "                    elif choice3 == \"exit\":\n",
    "                        exit_flag = False\n",
    "                    if choice3 in data[choice][choice2]:\n",
    "                            for i4 in data[choice][choice2][choice3]:\n",
    "                                print(\"\\t\\t\\t\",i4)\n",
    "                            choice4 = input(\"这是最后一层，返回输入'back'：\")\n",
    "                            if choice4 == \"back\":          # 返回上一层\n",
    "                                pass\n",
    "                            elif choice4 == \"exit\":\n",
    "                                exit_flag = False\n",
    "\n",
    "    elif choice == \"exit\":\n",
    "        exit_flag = False         # 结束\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "941d241e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
